home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / libgutil / unmesh.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  3KB  |  157 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    unmesh -
  19.  *        Convert tmesh calls into triangles.
  20.  *
  21.  *            Paul Haeberli - 1990
  22.  */
  23. #include "stdio.h"
  24.  
  25. static meshout_endpoly();
  26. static meshout_bgnpoly();
  27. static meshout_vert();
  28. static savemesh();
  29.  
  30. #define V_NULL            0
  31. #define V_FIRSTTMESH        1
  32. #define V_SECONDTMESH        2
  33. #define V_THIRDTMESH        3
  34. #define V_TMESH            4
  35.  
  36. static int vmode = V_NULL;
  37. static int replaceb;
  38. static float *a, *b;
  39. static int (*meshcallback)();
  40. static int meshverts;
  41.  
  42. /*
  43.  *    Input functions
  44.  *
  45.  */
  46. mesh_callback(func)
  47. int (*func)();
  48. {
  49.     meshcallback = func;
  50. }
  51.  
  52. mesh_bgntmesh()
  53. {
  54.     vmode = V_FIRSTTMESH;
  55. }
  56.  
  57. mesh_endtmesh()
  58. {
  59.     switch (vmode) {
  60.     case V_SECONDTMESH:
  61.     case V_THIRDTMESH:
  62.         meshout_endpoly();
  63.         break;
  64.     default: break;
  65.     }
  66.     vmode = V_NULL;
  67. }
  68.  
  69. mesh_swaptmesh()
  70. {
  71.     replaceb = !replaceb;
  72. }
  73.  
  74. mesh_vert(v)
  75. float *v;
  76. {
  77.     float x,y,z;
  78.  
  79.     switch(vmode) {
  80.     case V_FIRSTTMESH:
  81.         meshout_bgnpoly();
  82.         meshout_vert(v);
  83.         replaceb = 0;
  84.         savemesh(v);
  85.         vmode = V_SECONDTMESH;
  86.         break;
  87.     case V_SECONDTMESH:
  88.         meshout_vert(v);
  89.         savemesh(v);
  90.         vmode = V_THIRDTMESH;
  91.         break;
  92.     case V_THIRDTMESH:
  93.         meshout_vert(v);
  94.         meshout_endpoly();
  95.         savemesh(v);
  96.         vmode = V_TMESH;
  97.         break;
  98.     case V_TMESH:
  99.         meshout_bgnpoly();
  100.         meshout_vert(v);
  101.         meshout_vert(a);
  102.         meshout_vert(b);
  103.         meshout_endpoly();
  104.         savemesh(v);
  105.         break;
  106.     }
  107. }                     
  108.                      
  109. static savemesh(v)
  110. float *v;
  111. {
  112.     if (!replaceb)
  113.     a = v;
  114.     else 
  115.     b = v;
  116.     replaceb = !replaceb;
  117. }
  118.  
  119. /*
  120.  *    output functions 
  121.  *
  122.  */
  123. static int meshpolyp;
  124. static long meshvert[3];
  125.  
  126. static meshout_bgnpoly()
  127. {
  128.     meshpolyp = 0;
  129. }
  130.  
  131. static meshout_vert(ptr)
  132. long ptr;
  133. {
  134.     float x, y, z;
  135.     int offset;
  136.  
  137.     meshvert[meshpolyp] = ptr;
  138.     meshpolyp++;
  139.     if(meshpolyp > 3) {
  140.     fprintf(stderr,"meshout_vert: too many verticies\n");
  141.     exit(1);
  142.     }
  143. }
  144.  
  145. static meshout_endpoly()
  146. {
  147.     if(meshpolyp != 3) {
  148.     fprintf(stderr,"meshout_endpoly: vert count not 3\n");
  149.     exit(1);
  150.     }
  151.     if(!meshcallback) {
  152.     fprintf(stderr,"meshout_endpoly: mesh call back not defined\n");
  153.     exit(1);
  154.     }
  155.     (meshcallback)(meshvert);
  156. }
  157.